class Flvjs {
  constructor (player) {
    this.player = player
  }

  setup ({file, isLive}) {
    this.flvPlayer = window.flvjs.createPlayer({
      type: 'flv',
      url: file,
      isLive
    })
    this.flvPlayer.attachMediaElement(this.player.dom.video)
    this.player.once('beforePlay', () => this.flvPlayer.load())
  }

  remove () {
    if (this.flvPlayer) {
      this.flvPlayer.detachMediaElement()
      this.flvPlayer.destroy()
    }
  }
}

Flvjs.formats = {
  'video/flv': 'FLV',
  'video/x-flv': 'FLV'
}

Flvjs.canPlayType = function (type) {
  if (window.flvjs.isSupported() && type in Flvjs.formats) {
    return 'maybe'
  }

  return ''
}

Flvjs.canPlaySource = function (srcObj, options) {
  return Flvjs.canPlayType(srcObj.type)
}

Flvjs.VERSION = '__VERSION__'

export default Flvjs
